//
//  YDHomeOptionsCell.m
//  siyanone
//
//  Created by LK-IOS on 2018/3/27.
//  Copyright © 2018年 LK-News. All rights reserved.
//

#import "YDHomeOptionsCell.h"
#import "YDHomeOptionsDynamicModel.h"


@interface YDHomeOptionsCell()


//分割线
@property (nonatomic , weak) UIView *lineView;
//股票名称
@property (nonatomic , weak) UILabel *stockName;
//股票代码
@property (nonatomic , weak) UILabel *stockCode;
//买入卖出状态
@property (nonatomic , weak) UIImageView *saleStatusImage;
//用户手机号
@property (nonatomic , weak) UILabel *userLabel;
//盈利状态
@property (nonatomic , weak) UILabel *profitStatus;
//点买按钮
@property (nonatomic , weak) SYNoHeightedButton *saleButton;


@end



@implementation YDHomeOptionsCell


-(void)setModel:(YDHomeOptionsDynamicModel *)model
{
    _model = model;
    //名称及代码
    self.stockName.text = model.stockName;
    self.stockCode.text = model.stockCode;
    
    self.userLabel.text = model.phone;
    
    if ([model.tradeType isEqualToString:@"2"]) {
        self.saleStatusImage.image = [UIImage imageNamed:@"cc-yipingcang"];
    }else{
        self.saleStatusImage.image = [UIImage imageNamed:@"cc-yipingcangmairu"];
    }
    
    
    //盈利状态
    self.profitStatus.text = model.pzProfitString;
    
    if ([model.pzProfitString containsString:@"---"] || [model.pzProfitString containsString:@"名义本金"]) {
        self.profitStatus.textColor = [UIColor colorWithHexString:blueyGrey];
    }else{
        self.profitStatus.textColor = [UIColor colorWithHexString:paleRed];
    }
    
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *homeOptionsCell = @"YDHomeOptionsCell";
    YDHomeOptionsCell *cell = [tableView dequeueReusableCellWithIdentifier:homeOptionsCell];
    if (cell == nil) {
        cell = [[YDHomeOptionsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:homeOptionsCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.backgroundColor = [UIColor whiteColor];
        
        [self lineView];
        [self stockName];//股票名称
        [self stockCode];//股票代码
        [self saleStatusImage];//买入卖出状态
        
        [self userLabel];//用户手机号
        [self profitStatus];//盈利状态
        [self saleButton];//点买按钮
    }
    return self;
}
/****股票名称*****/
-(UILabel *)stockName
{
    if (_stockName == nil) {
        UILabel *stockName = [[UILabel alloc] init];
        [self.contentView addSubview:stockName];
        stockName.textColor = [UIColor colorWithHexString:dark];
        stockName.font = [UIFont systemFontOfSize:font16ScreenWRate * LKScreenW];
        stockName.textAlignment = NSTextAlignmentLeft;
        stockName.text = @"上海物贸";
        [stockName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(rate375(15));
            if (isPhoneX) {
                make.top.equalTo(self).offset(rateX812(15));
            }else{
                make.top.equalTo(self).offset(rate750(15));
            }
        }];
        _stockName = stockName;
    }
    return _stockName;
}
/****股票代码*****/
-(UILabel *)stockCode
{
    if (_stockCode == nil) {
        UILabel *stockCode = [[UILabel alloc] init];
        [self.contentView addSubview:stockCode];
        stockCode.textColor = [UIColor colorWithHexString:blueyGrey];
        stockCode.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
        stockCode.textAlignment = NSTextAlignmentLeft;
        stockCode.text = @"000001";
        [stockCode mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.stockName.mas_right).offset(rate375(8));
            make.centerY.equalTo(self.stockName);
        }];
        _stockCode = stockCode;
    }
    return _stockCode;
}
/****买入卖出状态*****/
-(UIImageView *)saleStatusImage
{
    if (_saleStatusImage == nil) {
        UIImageView *saleStatusImage = [[UIImageView alloc] init];
        [self.contentView addSubview:saleStatusImage];
        saleStatusImage.image = [UIImage imageNamed:@"cc-yipingcang"];
        [saleStatusImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.stockName);
            if (isPhoneX) {
                make.top.equalTo(self.stockName.mas_bottom).offset(rateX812(3));
            }else{
                make.top.equalTo(self.stockName.mas_bottom).offset(rate750(3));
            }
        }];
        _saleStatusImage = saleStatusImage;
    }
    return _saleStatusImage;
}
/****用户手机号*****/
-(UILabel *)userLabel
{
    if (_userLabel == nil) {
        UILabel *userLabel = [[UILabel alloc] init];
        [self.contentView addSubview:userLabel];
        userLabel.textColor = [UIColor colorWithHexString:frenchBlue];
        userLabel.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
        userLabel.textAlignment = NSTextAlignmentLeft;
        userLabel.text = @"138****3838";
        [userLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.saleStatusImage.mas_right).offset(rate375(10));
            make.centerY.equalTo(self.saleStatusImage);
        }];
        _userLabel = userLabel;
    }
    return _userLabel;
}
/****盈利状态*****/
-(UILabel *)profitStatus
{
    if (_profitStatus == nil) {
        UILabel *profitStatus = [[UILabel alloc] init];
        [self.contentView addSubview:profitStatus];
        profitStatus.textColor = [UIColor colorWithHexString:paleRed];
        profitStatus.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        profitStatus.textAlignment = NSTextAlignmentCenter;
        profitStatus.text = @"盈利500元";
        [profitStatus mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(self.userLabel.mas_right).offset(rate375(20));
            make.width.equalTo(@(rate375(130)));
        }];
        profitStatus.adjustsFontSizeToFitWidth = YES;
        _profitStatus = profitStatus;
    }
    return _profitStatus;
}
/****点买按钮*****/
-(SYNoHeightedButton *)saleButton
{
    if (_saleButton == nil) {
        SYNoHeightedButton *saleButton = [SYNoHeightedButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:saleButton];
        saleButton.backgroundColor = [UIColor colorWithHexString:Orange];
        [saleButton setTitle:@"策略申购" forState:UIControlStateNormal];
        [saleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        saleButton.titleLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        saleButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        saleButton.titleLabel.adjustsFontSizeToFitWidth = YES;
        [saleButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.width.equalTo(@(rate375(74)));
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(26)));
            }else{
                make.height.equalTo(@(rate750(26)));
            }
            make.right.equalTo(self).offset(-rate375(15));
        }];
        saleButton.layer.cornerRadius = 3.0;
        saleButton.layer.masksToBounds = YES;
        [saleButton addTarget:self action:@selector(saleButtonClick) forControlEvents:UIControlEventTouchDown];
        _saleButton = saleButton;
    }
    return _saleButton;
}


-(void)saleButtonClick
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(homeOptionsCellSaleButtonClick:)]) {
        [self.delegate homeOptionsCellSaleButtonClick:self];
    }
}


-(UIView *)lineView
{
    if (_lineView == nil) {
        UIView *lineView = [[UIView alloc] init];
        [self.contentView addSubview:lineView];
        lineView.backgroundColor = NumberColor(247, 247, 247);
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self);
            make.height.equalTo(@1);
        }];
        _lineView = lineView;
    }
    return _lineView;
}


@end
